package com.peng.leetcode.tree;

/**
 * IsUnivalTree
 *
 * 965. 单值二叉树
 *
 * @author: lupeng6
 * @create: 2021/5/7 14:53
 */
public class IsUnivalTree {

    public static void main(String[] args) {

    }


    public boolean isUnivalTree(TreeNode root) {
        if (root == null) {
            return true;
        }
        return help(root, root.val);
    }

    private boolean help(TreeNode node, int val) {
        if (node == null) {
            return true;
        }
        if (node.val != val) {
            return false;
        }
        if (help(node.left, val) && help(node.right, val)) {
            return true;
        } else {
            return false;
        }
    }
}
